<?php
//比较运算符
$br = "<br/>\n";
$br2 = str_repeat($br, 2);

echo 'PHP8 数字和字符串比较 字符串是非数字字符串 按字符串比较' . $br;
echo 'PHP7 数字和字符串比较 将字符串转化为int比较' . $br;
echo 'PHP7和PHP8 两个都是数字字符串 将字符串转化为int比较' . $br;

echo PHP_VERSION . $br;
echo '数字和字符串比较 ' . $br;
echo '0 == "abc" false ' . $br;
var_dump(0 == "abc", "abc" == 0);
echo '0 == "" false ' , $br ;
var_dump(0 == "", "" == 0);
echo '0 == "0" true', $br;
var_dump(0 == "0", "0" == 0);
echo '"1" == "01" ', $br;
var_dump("1" == "01");
echo '1 == "01" ', $br;
var_dump(1 == "01");
echo '1 == "0abc" ', $br;
var_dump(0 == "0abc");


echo "---------------", $br;
//php7和php8的不同
//数字和字符串比较
var_dump((int)"a",(string)0, (int)"abc", (int)"123abc", '0 == "a"',0 == "a");
//数字和非数字字符串比较
var_dump('123 == "123ab"', 123 == "123ab");

//数字字符串和非数字字符串间比较按字符串比较
var_dump('"123" == "123ab"', "123" == "123ab", "123cd" == "123ab");

/**
 * 计算 数字字符串和数字 做运算 转换为数字
 */
$index = '01' +1;
var_dump(sprintf('%02d', $index), $index);


//php7和php8的不同
//数字和字符串比较
var_dump('0 == "a"',0 == "a", (int)"a",(string)0);
//数字和数字字符串比较
var_dump('123 == "123ab"', 123 == "123ab", 123 == "123");

//数字字符串间比较
var_dump('"123" == "123ab"', "123" == "123ab", "123cd" == "123ab");
